<?php

class Damages_Methods_Request_Edit_DamageType extends Damages_Methods_Request {

  /**
   *
   * @var Damages_Methods_Data_Dictionary_DamageType_Edit 
   */
  public $obj;

  public function __construct($params) {
    $this->obj = new Damages_Methods_Data_Dictionary_DamageType_Edit($params->obj);
    parent::__construct($params);
  }

  public function process() {
    if (!Damages_Auth::getInstance()->checkPermission(Damages_Auth::PERMISSION_ADMIN))
      throw new Damages_Exception_App(Damages_Codes::ACCESS_DENIED);
    $obj = DamagesDictDamageTypesQuery::create()->findOneById($this->obj->id);
    if (!$obj instanceof DamagesDictDamageTypes)
      throw new Damages_Exception_App(Damages_Codes::DB_OBJECT_NOT_FOUND, array($this->obj->id));
    $obj->setName($this->obj->name);
    $obj->setNameEn($this->obj->nameEn);
    $obj->setCode($this->obj->code);
    $obj->save();
    $response = new Damages_Methods_Response_GetDictionaries(true);
    $response->setDamageTypes();
    return $response;
  }

}